import Vue from 'vue'
import Router from 'vue-router'


// import home from '@/components/home/home';//主页
// import login from '@/components/login/login';//登陆
// import programList from '@/components/template/program/programList';//小程序管理
// import DataChannel from '@/components/template/program/censusList';//数据统计
// import channelList from '@/components/template/channel/channelList';//添加渠道
// import ChannelStatistics from '@/components/template/channel/censusList';//渠道统计
// import operateList from '@/components/template/operate/operateList';//运营配置
// import userList from '@/components/template/user/userList';//用户资料
// import jumpProgramList from '@/components/template/jump_program/jumpProgramList';//跳转管理




const home = resolve => require(['@/components/home/home'], resolve);//主页
const login = resolve => require(['@/components/login/login'], resolve);//登陆
const programList = resolve => require(['@/components/template/program/programList'], resolve);//小程序管理
const DataChannel = resolve => require(['@/components/template/program/censusList'], resolve);//数据统计
const channelList = resolve => require(['@/components/template/channel/channelList'], resolve);//添加渠道
const ChannelStatistics = resolve => require(['@/components/template/channel/censusList'], resolve);//渠道统计
const operateList = resolve => require(['@/components/template/operate/operateList'], resolve);//运营配置
const userList = resolve => require(['@/components/template/user/userList'], resolve);//用户资料
const jumpProgramList = resolve => require(['@/components/template/jump_program/jumpProgramList'], resolve);//跳转管理
const exchangeGoods = resolve => require(['@/components/template/goods/exchangeGoods'], resolve);//兑换商品
const lotteryDraw = resolve => require(['@/components/template/activity/lotteryDraw'], resolve);//抽奖配置




const shareConfig = resolve => require(['@/components/template/share/shareConfig'], resolve);//分享配置
const shareCensusList = resolve => require(['@/components/template/share/shareCensusList'], resolve);//分享配置
const newsList = resolve => require(['@/components/template/news/newsList'], resolve);//资讯列表
const newsCensusList = resolve => require(['@/components/template/news/newsCensusList'], resolve);//资讯统计
const newsCommentList = resolve => require(['@/components/template/news/newsCommentList'], resolve);//评论管理
const newsDetails = resolve => require(['@/components/template/news/newsDetails'], resolve);//资讯列表详情
const newsImg = resolve => require(['@/components/template/news/newsImg'], resolve);//资讯列表图集

const templateList = resolve => require(['@/components/template/template/templateList'], resolve);//模板消息
















Vue.use(Router)


const routes = [
    {
      	path: '/login/login',
      	name: 'login',
		component: login,
	},
	{
		path: '/',
		name: 'home',
		component: home,
		redirect:"/template/program/programList",
		children:[
			{
				path: '/template/program/programList',	
				name: 'programList',
				component: programList
			},
			{
				path: '/template/program/censusList',	
				name: 'DataChannel',
				component: DataChannel
			},
			{
				path: '/template/channel/channelList',	
				name: 'channelList',
				component: channelList
			},
			{
				path: '/template/channel/censusList',	
				name: 'ChannelStatistics',
				component: ChannelStatistics
			},
			{
				path: '/template/operate/operateList',	
				name: 'operateList',
				component: operateList
			},
			{
				path: '/template/user/userList',	
				name: 'userList',
				component: userList
			},
			{
				path: '/template/jump_program/jumpProgramList',	
				name: 'jumpProgramList',
				component: jumpProgramList
			},
			{
				path: '/template/goods/exchangeGoods',	
				name: 'exchangeGoods',
				component: exchangeGoods
			},
			{
				path: '/template/activity/lotteryDraw',	
				name: 'lotteryDraw',
				component: lotteryDraw
			},
			{
				path: '/template/share/shareConfig',	
				name: 'shareConfig',
				component: shareConfig
			},
			{
				path: '/template/share/shareCensusList',	
				name: 'shareCensusList',
				component: shareCensusList
			},
			{
				path: '/template/news/newsList',	
				name: 'newsList',
				component: newsList
			},
			{
				path: '/template/news/newsCensusList',	
				name: 'newsCensusList',
				component: newsCensusList
			},
			{
				path: '/template/news/newsCommentList',	
				name: 'newsCommentList',
				component: newsCommentList
			},
			{
				path: '/template/news/newsDetails',	
				name: 'newsDetails',
				component: newsDetails
			},
			{
				path: '/template/news/newsImg',	
				name: 'newsImg',
				component: newsImg
			},
			{
				path: '/template/template/templateList',	
				name: 'templateList',
				component: templateList
			}
		]
	}
  ]


const router   = new Router({
	routes
})



router.beforeEach((to, from, next) => {
	let USER_INFO = sessionStorage.getItem('USER_INFO');
	if(to.path == '/login/login'){
		next()
	}
	else{
		if(!USER_INFO || USER_INFO == null){
			next({ path: '/login/login' })
		}
		else{
			next()
		}
		
	}
})

export default router